package com.example.miniodemo.common.exception;

import com.example.miniodemo.common.result.Result;
import com.example.miniodemo.common.result.ResultEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 前端返回值异常处理类
 *
 * @author Lv
 * @date 2022/11/4
 */
@RestControllerAdvice(basePackages = "com.example.miniodemo")
public class ResultExceptionHandler {
    /**
     * 全局异常捕捉
     *
     * @param exception 异常
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result<?> exception(Exception exception) {
        String message = exception.getMessage();
        exception.printStackTrace();
        return Result.failed(ResultEnum.PARAM_REQUIRE, message);
    }
}
